package ag.integration;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceHolder.Callback;

public class MyView extends SurfaceView implements Callback{
	public SurfaceHolder holder;
	MainActivity activity;
	
	public MyView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.activity = (MainActivity)context;
		holder = this.getHolder();
		holder.addCallback(this);
	}
	
	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		//canvas.drawLine(startX, startY, stopX, stopY, paint)
		Log.d("ag-surfaceview", "surfaceview surfaceCreated");
	}
	
	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		//_engine.stop();
		Log.d("ag-surfaceview", "surfaceview surfaceDestroyed");
	}
	
	 public Bitmap loadImage(int fileid, int width, int height) {
		 Resources r = this.getContext().getResources();
		 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
		 Drawable drawable = r.getDrawable(fileid);
		 Canvas canvas = new Canvas(bitmap);
		 drawable.setBounds(0, 0, width, height);
		 drawable.draw(canvas);
		 return bitmap;
	 }
	 
	 public Bitmap loadImage(int resid) {
		 Resources r = this.getContext().getResources();
		 Drawable drawable = r.getDrawable(resid);
		 int width = drawable.getIntrinsicWidth(); 
		 int height = drawable.getIntrinsicHeight(); 
		 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
		 Canvas canvas = new Canvas(bitmap);
		 drawable.setBounds(0, 0, width, height);
		 drawable.draw(canvas);
		 return bitmap;
	 }
	 
	 public Bitmap getRes(String name) {
		 Bitmap bitmap=BitmapFactory.decodeStream(getClass().getResourceAsStream(name));
		 return bitmap;
	 }
}
